<template>
  <div class="tab-contorl">
    <div v-for="(item,index) of titles" :key="index" class="tab-contorl-item" :class="{active:index===CurrentIndex}"
      @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      titles: {
        type: Array,
        default () {
          return []
        }
      }
    },
    data() {
      return {
        CurrentIndex: 0
      }
    },
    methods: {
      itemClick(index) {
        this.CurrentIndex = index
        // 子组件传父组件 切换的时候显示数据
        this.$emit('tabClick', index)
      }
    }
  }
</script>

<style scoped lang="less">
  .tab-contorl {
    display: flex;
    text-align: center;
    line-height: 40px;
    font-size: 16px;
    height: 40px;
  }

  .tab-contorl-item {
    flex: 1;
  }

  .tab-contorl-item span {
    padding: 5px;
  }

  .active {
    color: rgb(201, 21, 81);
  }

  .active span {
    border-bottom: 1px solid rgb(201, 21, 81);
  }
</style>